package com.example.kt_fast.ui

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.example.kt_common.base.BaseVMFragment
import com.example.kt_common.util.Constants
import com.example.kt_common.util.ToastUtil
import com.example.kt_fast.R
import com.example.kt_fast.databinding.FragmentFastBinding
import com.example.kt_fast.adapter.FastItemClickListener
import com.example.kt_fast.adapter.FastRVAdapter
import com.example.kt_fast.bean.FastBean


class FastFragment : BaseVMFragment<FragmentFastBinding>() {
    //   private val fastViewModel: hom
    lateinit var fastRVAdapter: FastRVAdapter
    lateinit var gridLayoutManager: GridLayoutManager
    var list: MutableList<FastBean> = mutableListOf()
    override fun observe() {
        list.add(
            FastBean(
                resources.getString(R.string.single_monitoring),
                com.example.kt_common.R.drawable.icon_marka_online
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.multiple_monitoring),
                com.example.kt_common.R.drawable.icon_marka_mutil
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.real_video),
                com.example.kt_common.R.drawable.ic_shiping
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.historical_trajectory),
                com.example.kt_common.R.drawable.ic_historical_trajectory
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.video_replay),
                com.example.kt_common.R.drawable.ic_replay
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.feedback), com.example.kt_common.R.drawable.ic_feedback
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.add_driver),
                com.example.kt_common.R.drawable.ic_add_driver
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.realtime_warm),
                com.example.kt_common.R.drawable.ic_alarm_query
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.overall_data),
                com.example.kt_common.R.drawable.ic_overalldata
            )
        )
        list.add(
            FastBean(
                resources.getString(R.string.nearby_charging_station),
                com.example.kt_common.R.drawable.ic_charing
            )
        )

    }

    override fun init() {
        //创建布局管理器
        gridLayoutManager = GridLayoutManager(activity, 2, RecyclerView.VERTICAL, false)
        //设置布局管理器
        mBind.bottomView.layoutManager = gridLayoutManager
        fastRVAdapter = FastRVAdapter(object : FastItemClickListener {
            override fun onItemClick(position: Int) {
                when (position) {
                    0->{
                        ARouter.getInstance().build(Constants.PATH_CAR_TREE).navigation()
                    }
                    6 -> {
                        ARouter.getInstance().build(Constants.PATH_ADD_DRIVER).navigation()
                    }
                    else -> ToastUtil.showMsg("点击了item $position")
                }
            }
        })
        fastRVAdapter.setData(list)
        mBind.bottomView.adapter = fastRVAdapter
    }

    override fun getLayoutID(): Int {
        return R.layout.fragment_fast
    }

}